import axios from '../utils/http'

const GoodsStore = {
    namespaced: true,
    state:()=>({
        goods_list: [],
        goods_count: 0
    }),
    mutations: {
        GoodsListMutations(state,list){
            state.goods_list = list
        },
        GoodsCountMutations(state,count){
            state.goods_count = count
        }
    },
    actions:{
        GoodsListActions(context,page={page: 1,page_size: 5}){
            var url = "/api/goodslist?page="+page.page+"&size="+page.page_size
            axios.get(url).then(res=>{
                if(res.code === 200){
                    context.commit("GoodsListMutations",res.list)
                }
            })
        },   
        GoodsCountActions(context){
            var url = "/api/goodscount"
            axios.get(url).then(res=>{
                if(res.code === 200){
                    context.commit('GoodsCountMutations',res.list[0].total)
                }
            })
        }
    }
}

export default GoodsStore